/**
 * Author: Shen Yanqiu
 * Date: 2017-12-13
 * Time: 18:23
 *
 */
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'dva';
import { Page } from 'components';
import queryString from 'query-string';
import { Operation, List } from './Components';
import { message } from 'antd';

class Repository extends React.Component {
  static propTypes = {
    loading: PropTypes.object,
    dispatch: PropTypes.func,
    repository: PropTypes.object,
    app: PropTypes.object,
    location: PropTypes.object,
  };
  state = {
    deleteArray: [],
  };
  getCheckbox = (data) => {
    console.log(data);
    this.setState({
      deleteArray: data,
    });
  };
  render () {
    const { loading, location, repository, dispatch, app } = this.props;
    location.query = queryString.parse(location.search);
    const { list, pagination } = repository;
    const listProps = {
      dataSource: list,
      loading: loading.effects['repository/getWorknoticeList'],
      pagination,

      onChange (_pagination) {
        const { query, pathname } = location;
        dispatch({
          type: 'repository/getWorknoticeList',
          payload: {
            ...query,
            current: _pagination.current,
            pageSize: _pagination.pageSize,
          },
        });
      },
      onSeeItem (id) {
        dispatch({
          type: 'repository/onSeeItemModal',
          payload: {
            id,
          },
        });
      },

      onDeleteItem (id) {
        dispatch({
          type: 'repository/onDeleteItemModal',
          payload: {
            params: {
              id,
            },
          },
        });
      },
    };
    // 点击搜索触发请求数据
    const SearchData = (data) => {
      dispatch({
        type: 'repository/searchData',
        payload: {
          formData: data,
        },
      });
    };
    // 创建文件夹
    const createFolder = (values) => {
      console.log(values);
    };
    // 批量删除
    const remove = () => {
      if (this.state.deleteArray.length === 0) {
        message.error("请先选择需要删除的信息");
        return;
      }
      // dispatch({
      //   type: 'repository/onDeleteItemModal',
      //   payload: {
      //     params: {
      //       ids: this.state.deleteArray,
      //     },
      //   },
      // });
    };
    const operationProps = {
      SearchData,
      createFolder,
      remove,
      // accesstoken: app.auth.accessToken,
    };
    return (
      <Page loading={loading.models.repository}>
        <Operation {...operationProps} />
        <List {...listProps} getCheckbox={this.getCheckbox} />
      </Page>
    );
  }
}


export default connect(({ loading, repository, app }) => ({ loading, repository, app }))(Repository);
